// app.ts
App<IAppOption>({
  globalData: {},
  onLaunch() {
    const self = this;
    //初始化云服务环境
    wx.cloud.init({
      env: 'cloud1-9gvsip401a78055c',
      traceUser: true
    })

    // 登录
    wx.login({
      success: res => {
        console.log(res.code)
      }
    })

    //获取微信ID
    wx.cloud.callFunction({
      name: 'getOpenId'
    }).then(res => {
      // 检查 res.result 是否为对象且包含 openid 属性
      self.globalData.userId = res.result.userInfo.openId;

      if (self.openidReadyCallback) {
        self.openidReadyCallback(res.result.userInfo.openId);
      }
    }).catch(err => {
      console.error("获取 openid 失败：", err);
    });
  },
})